Skip to content

Conversation

jhuber6
Copy link
Contributor

@jhuber6 jhuber6 commented Sep 19, 2025

Summary:
The AMDGPU hack can be removed, and we no longer need to skip 90% of the
HandleLLVMOptions if we work around NVPTX earlier. Simplifies the
interface by removing duplicated logic and keeps the GPU targets from
being weirdly divergent on some flags.

Summary:
The AMDGPU hack can be removed, and we no longer need to skip 90% of the
`HandleLLVMOptions` if we work around NVPTX earlier. Simplifies the
interface by removing duplicated logic and keeps the GPU targets from
being weirdly divergent on some flags.
@jhuber6 jhuber6 requested a review from a team as a code owner September 19, 2025 15:53
@llvmbot llvmbot added cmake Build system in general and CMake in particular compiler-rt libc openmp:libomp OpenMP host runtime openmp:libomptarget OpenMP offload runtime labels Sep 19, 2025
@llvmbot
Copy link
Member

llvmbot commented Sep 19, 2025

@llvm/pr-subscribers-libc

Author: Joseph Huber (jhuber6)

Changes

Summary:
The AMDGPU hack can be removed, and we no longer need to skip 90% of the
HandleLLVMOptions if we work around NVPTX earlier. Simplifies the
interface by removing duplicated logic and keeps the GPU targets from
being weirdly divergent on some flags.


Full diff: https://github.com/llvm/llvm-project/pull/159802.diff

6 Files Affected:

  • (modified) compiler-rt/cmake/Modules/CompilerRTUtils.cmake (+1-3)
  • (modified) flang-rt/CMakeLists.txt (-9)
  • (modified) libc/cmake/modules/prepare_libc_gpu_build.cmake (-6)
  • (modified) llvm/cmake/modules/HandleLLVMOptions.cmake (-6)
  • (modified) openmp/CMakeLists.txt (-8)
  • (modified) runtimes/CMakeLists.txt (+5-6)
diff --git a/compiler-rt/cmake/Modules/CompilerRTUtils.cmake b/compiler-rt/cmake/Modules/CompilerRTUtils.cmake
index 03db38fa4cdc1..cbd18d26c0b93 100644
--- a/compiler-rt/cmake/Modules/CompilerRTUtils.cmake
+++ b/compiler-rt/cmake/Modules/CompilerRTUtils.cmake
@@ -418,11 +418,9 @@ macro(construct_compiler_rt_default_triple)
     # Pass the necessary flags to make flag detection work.
     if("${COMPILER_RT_DEFAULT_TARGET_ARCH}" MATCHES "amdgcn")
       set(COMPILER_RT_GPU_BUILD ON)
-      set(CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS} -nogpulib")
     elseif("${COMPILER_RT_DEFAULT_TARGET_ARCH}" MATCHES "nvptx")
       set(COMPILER_RT_GPU_BUILD ON)
-      set(CMAKE_REQUIRED_FLAGS
-          "${CMAKE_REQUIRED_FLAGS} -flto -c -Wno-unused-command-line-argument")
+      set(CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS} -flto -c")
     endif()
   endif()
 
diff --git a/flang-rt/CMakeLists.txt b/flang-rt/CMakeLists.txt
index a45a66be6f833..cad39d0c71016 100644
--- a/flang-rt/CMakeLists.txt
+++ b/flang-rt/CMakeLists.txt
@@ -221,15 +221,6 @@ endif()
 # System Introspection #
 ########################
 
-# The GPU targets require a few mandatory arguments to make the standard CMake
-# check flags happy.
-if ("${LLVM_RUNTIMES_TARGET}" MATCHES "^amdgcn")
-  set(CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS} -nogpulib")
-elseif ("${LLVM_RUNTIMES_TARGET}" MATCHES "^nvptx")
-  set(CMAKE_REQUIRED_FLAGS
-      "${CMAKE_REQUIRED_FLAGS} -flto -c -Wno-unused-command-line-argument")
-endif()
-
 include(CheckCXXSymbolExists)
 include(CheckCXXSourceCompiles)
 check_cxx_symbol_exists(strerror_r string.h HAVE_STRERROR_R)
diff --git a/libc/cmake/modules/prepare_libc_gpu_build.cmake b/libc/cmake/modules/prepare_libc_gpu_build.cmake
index df1de1454c3eb..4d12a5917a56f 100644
--- a/libc/cmake/modules/prepare_libc_gpu_build.cmake
+++ b/libc/cmake/modules/prepare_libc_gpu_build.cmake
@@ -20,12 +20,6 @@ endif()
 if(LIBC_TARGET_TRIPLE)
   set(CMAKE_REQUIRED_FLAGS "--target=${LIBC_TARGET_TRIPLE}")
 endif()
-if(LIBC_TARGET_ARCHITECTURE_IS_AMDGPU)
-  set(CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS} -nogpulib")
-elseif(LIBC_TARGET_ARCHITECTURE_IS_NVPTX)
-  set(CMAKE_REQUIRED_FLAGS
-      "${CMAKE_REQUIRED_FLAGS} -flto -c -Wno-unused-command-line-argument")
-endif()
 
 # Optionally set up a job pool to limit the number of GPU tests run in parallel.
 # This is sometimes necessary as running too many tests in parallel can cause
diff --git a/llvm/cmake/modules/HandleLLVMOptions.cmake b/llvm/cmake/modules/HandleLLVMOptions.cmake
index 24142c934b918..ba82f72df4f1e 100644
--- a/llvm/cmake/modules/HandleLLVMOptions.cmake
+++ b/llvm/cmake/modules/HandleLLVMOptions.cmake
@@ -144,12 +144,6 @@ if( LLVM_ENABLE_ASSERTIONS )
   endif()
 endif()
 
-# If we are targeting a GPU architecture in a runtimes build we want to ignore
-# all the standard flag handling.
-if(LLVM_RUNTIMES_GPU_BUILD)
-  return()
-endif()
-
 if(LLVM_ENABLE_EXPENSIVE_CHECKS)
   # When LLVM_ENABLE_EXPENSIVE_CHECKS is ON, LLVM will intercept errors
   # using assert(). An explicit check is performed here.
diff --git a/openmp/CMakeLists.txt b/openmp/CMakeLists.txt
index 1358e896d3cc5..a2b7e1054e02b 100644
--- a/openmp/CMakeLists.txt
+++ b/openmp/CMakeLists.txt
@@ -99,14 +99,6 @@ else()
   set(CMAKE_CXX_EXTENSIONS NO)
 endif()
 
-# Targeting the GPU directly requires a few flags to make CMake happy.
-if("${CMAKE_CXX_COMPILER_TARGET}" MATCHES "^amdgcn")
-  set(CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS} -nogpulib")
-elseif("${CMAKE_CXX_COMPILER_TARGET}" MATCHES "^nvptx")
-  set(CMAKE_REQUIRED_FLAGS
-      "${CMAKE_REQUIRED_FLAGS} -flto -c -Wno-unused-command-line-argument")
-endif()
-
 # Check and set up common compiler flags.
 include(config-ix)
 include(HandleOpenMPOptions)
diff --git a/runtimes/CMakeLists.txt b/runtimes/CMakeLists.txt
index 45a6517737b95..fac621a076aa4 100644
--- a/runtimes/CMakeLists.txt
+++ b/runtimes/CMakeLists.txt
@@ -181,15 +181,14 @@ if ("${CMAKE_CXX_COMPILER_ID}" MATCHES "Clang")
   endif()
 endif()
 
+# The NVPTX target needs to override linking to pass compiler flag checks.
+if("${LLVM_RUNTIMES_TARGET}" MATCHES "^nvptx")
+  set(CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS} -flto -c")
+endif()
+
 # Avoid checking whether the compiler is working.
 set(LLVM_COMPILER_CHECKED ON)
 
-# This can be used to detect whether we're targeting a GPU architecture.
-if("${LLVM_RUNTIMES_TARGET}" MATCHES "^amdgcn" OR
-   "${LLVM_RUNTIMES_TARGET}" MATCHES "^nvptx64")
-  set(LLVM_RUNTIMES_GPU_BUILD ON)
-endif()
-
 # Handle common options used by all runtimes.
 include(AddLLVM)
 include(HandleLLVMOptions)

@jhuber6 jhuber6 requested review from compnerd and lntue September 19, 2025 15:54
@jhuber6
Copy link
Contributor Author

jhuber6 commented Sep 19, 2025

libcxx failure are unrelated

Copy link
Contributor

@michaelrj-google michaelrj-google left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM from the libc side

@jhuber6 jhuber6 merged commit 2d503b9 into llvm:main Sep 19, 2025
82 of 88 checks passed
@jhuber6 jhuber6 deleted the gpu_runtimes branch September 19, 2025 18:11
@llvm-ci
Copy link
Collaborator

llvm-ci commented Sep 20, 2025

LLVM Buildbot has detected a new failure on builder lldb-arm-ubuntu running on linaro-lldb-arm-ubuntu while building compiler-rt,flang-rt,libc,llvm,openmp,runtimes at step 6 "test".

Full details are available at: https://lab.llvm.org/buildbot/#/builders/18/builds/21326

Here is the relevant piece of the build log for the reference
Step 6 (test) failure: build (failure)
...
PASS: lldb-unit :: Core/./LLDBCoreTests/92/470 (2439 of 3673)
PASS: lldb-unit :: Core/./LLDBCoreTests/94/470 (2440 of 3673)
PASS: lldb-unit :: Core/./LLDBCoreTests/93/470 (2441 of 3673)
PASS: lldb-unit :: Core/./LLDBCoreTests/95/470 (2442 of 3673)
PASS: lldb-unit :: Core/./LLDBCoreTests/96/470 (2443 of 3673)
PASS: lldb-unit :: Core/./LLDBCoreTests/97/470 (2444 of 3673)
PASS: lldb-unit :: Core/./LLDBCoreTests/98/470 (2445 of 3673)
PASS: lldb-unit :: DAP/./DAPTests/1/76 (2446 of 3673)
PASS: lldb-unit :: Core/./LLDBCoreTests/99/470 (2447 of 3673)
PASS: lldb-unit :: DAP/./DAPTests/0/76 (2448 of 3673)
FAIL: lldb-unit :: DAP/./DAPTests/10/76 (2449 of 3673)
******************** TEST 'lldb-unit :: DAP/./DAPTests/10/76' FAILED ********************
Script(shard):
--
GTEST_OUTPUT=json:/home/tcwg-buildbot/worker/lldb-arm-ubuntu/build/tools/lldb/unittests/DAP/./DAPTests-lldb-unit-3345176-10-76.json GTEST_SHUFFLE=0 GTEST_TOTAL_SHARDS=76 GTEST_SHARD_INDEX=10 /home/tcwg-buildbot/worker/lldb-arm-ubuntu/build/tools/lldb/unittests/DAP/./DAPTests
--

Script:
--
/home/tcwg-buildbot/worker/lldb-arm-ubuntu/build/tools/lldb/unittests/DAP/./DAPTests --gtest_filter=DisconnectRequestHandlerTest.DisconnectTriggersTerminateCommands
--
../llvm-project/lldb/unittests/DAP/Handler/DisconnectTest.cpp:51: Failure
Actual function call count doesn't match EXPECT_CALL(client, Received(Output("1\n")))...
         Expected: to be called once
           Actual: never called - unsatisfied and active

../llvm-project/lldb/unittests/DAP/Handler/DisconnectTest.cpp:52: Failure
Actual function call count doesn't match EXPECT_CALL(client, Received(Output("2\n")))...
         Expected: to be called twice
           Actual: called once - unsatisfied and active


../llvm-project/lldb/unittests/DAP/Handler/DisconnectTest.cpp:51
Actual function call count doesn't match EXPECT_CALL(client, Received(Output("1\n")))...
         Expected: to be called once
           Actual: never called - unsatisfied and active

../llvm-project/lldb/unittests/DAP/Handler/DisconnectTest.cpp:52
Actual function call count doesn't match EXPECT_CALL(client, Received(Output("2\n")))...
         Expected: to be called twice
           Actual: called once - unsatisfied and active



********************
PASS: lldb-unit :: DAP/./DAPTests/11/76 (2450 of 3673)
PASS: lldb-unit :: DAP/./DAPTests/12/76 (2451 of 3673)
PASS: lldb-unit :: DAP/./DAPTests/13/76 (2452 of 3673)
PASS: lldb-unit :: DAP/./DAPTests/14/76 (2453 of 3673)

YixingZhang007 pushed a commit to YixingZhang007/llvm-project that referenced this pull request Sep 27, 2025
Summary:
The AMDGPU hack can be removed, and we no longer need to skip 90% of the
`HandleLLVMOptions` if we work around NVPTX earlier. Simplifies the
interface by removing duplicated logic and keeps the GPU targets from
being weirdly divergent on some flags.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cmake Build system in general and CMake in particular compiler-rt libc openmp:libomp OpenMP host runtime openmp:libomptarget OpenMP offload runtime
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants